{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. else语句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入密码：8887\n",
      "密码不正确\n",
      "请输入密码：8889\n",
      "密码不正确\n",
      "请输入密码：8888\n",
      "密码正确\n"
     ]
    }
   ],
   "source": [
    "# 从键盘区录入密码，最多录入三次，如果正确就结束循环\n",
    "# else和for搭配使用\n",
    "for item in range(3):\n",
    "    pwd = input('请输入密码：')\n",
    "    if pwd == '8888':\n",
    "        print('密码正确')\n",
    "        break\n",
    "    else:\n",
    "        print('密码不正确')\n",
    "else:\n",
    "    print('对不起，三次密码均输入错误')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入密码：4563\n",
      "密码不正确\n",
      "请输入密码：1599\n",
      "密码不正确\n",
      "请输入密码：4513\n",
      "密码不正确\n",
      "对不起，三次密码均输入错误\n"
     ]
    }
   ],
   "source": [
    "# else和while搭配使用\n",
    "a = 0\n",
    "while a < 3:\n",
    "    # 条件执行体\n",
    "    pwd = input('请输入密码：')\n",
    "    if pwd == '8888':\n",
    "        print('密码正确')\n",
    "        break\n",
    "    else:\n",
    "        print('密码不正确')\n",
    "    a += 1\n",
    "else:\n",
    "    print('对不起，三次密码均输入错误')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.6.3",
   "language": "python",
   "name": "python3.6.3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
